package net.fckeditor.requestcycle.impl;

import java.io.File;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import net.fckeditor.handlers.ConnectorHandler;
import net.fckeditor.requestcycle.UserPathBuilder;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;

/**
 * @author Xing,XiuDong
 * @version 2010-11-26
 */
public class UserPathBuilderImpl implements UserPathBuilder {

	public String getUserFilesPath(HttpServletRequest request) {

		String defaultUserFilesPath = ConnectorHandler.getDefaultUserFilesPath();
		defaultUserFilesPath = defaultUserFilesPath.replace("/", File.separator);

		String uploadDir = defaultUserFilesPath;

		String[] folderPatterns = new String[] { "", "yyyy", "MM", "dd" };
		String autoCreatedDateDir = DateFormatUtils
				.format(new Date(), StringUtils.join(folderPatterns, File.separator));

		return uploadDir + autoCreatedDateDir;
	}

}
